package org.liveboardgames.agricola.business.action.overrideaction;

import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.common.Target;

public class ActionOverrider {

  public Action overrideAction(Action action, Target target) {
    Action overriddenAction = action.clone();

    // Get the target of the action, i.e. the one that will benefit from it
    if (target != null) {
      overriddenAction.setTarget(target);
    }

    // Now override the action with player-specific data
    ActionOverride actionOverride = ActionOverrideFactory.getActionOverride(overriddenAction, target);
    if (actionOverride != null) {
      actionOverride.overrideAction();
    }

    return overriddenAction;
  }

}
